package com.linpq.road.controller;

import java.util.List;

import com.linpq.common.utils.ShiroUtils;
import com.linpq.road.domain.RdHighSpeedRoad;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.linpq.common.annotation.Log;
import com.linpq.common.enums.BusinessType;
import com.linpq.road.domain.RdMonitoringData;
import com.linpq.road.service.RdMonitoringDataService;
import com.linpq.common.core.controller.BaseController;
import com.linpq.common.core.domain.AjaxResult;
import com.linpq.common.utils.poi.ExcelUtil;
import com.linpq.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 检测数据Controller
 *
 * @author wunh
 * @date 2021-07-29
 */
@Controller
@RequestMapping("/road/monitoring_data")
public class RdMonitoringDataController extends BaseController {
    private String prefix = "road/monitoring_data";

    @Autowired
    private RdMonitoringDataService rdMonitoringDataService;

    @RequiresPermissions("road:monitoring_data:view")
    @GetMapping()
    public String monitoring_data() {
        return prefix + "/monitoring_data";
    }

    /**
     * 查询检测数据列表
     */
    @RequiresPermissions("road:monitoring_data:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RdMonitoringData rdMonitoringData) {
        startPage();
        List<RdMonitoringData> list = rdMonitoringDataService.selectRdMonitoringDataList(rdMonitoringData);
        return getDataTable(list);
    }

    /**
     * 导出检测数据列表
     */
    @RequiresPermissions("road:monitoring_data:export")
    @Log(title = "检测数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RdMonitoringData rdMonitoringData) {
        List<RdMonitoringData> list = rdMonitoringDataService.selectRdMonitoringDataList(rdMonitoringData);
        ExcelUtil<RdMonitoringData> util = new ExcelUtil<RdMonitoringData>(RdMonitoringData. class);
        return util.exportExcel(list, "monitoring_data");
    }

    /**
     * 新增检测数据
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存检测数据
     */
    @RequiresPermissions("road:monitoring_data:add")
    @Log(title = "检测数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RdMonitoringData rdMonitoringData) {
        return toAjax(rdMonitoringDataService.insertRdMonitoringData(rdMonitoringData));
    }

    /**
     * 修改检测数据
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        RdMonitoringData rdMonitoringData =rdMonitoringDataService.selectRdMonitoringDataById(id);
        mmap.put("rdMonitoringData", rdMonitoringData);
        return prefix + "/edit";
    }

    /**
     * 修改保存检测数据
     */
    @RequiresPermissions("road:monitoring_data:edit")
    @Log(title = "检测数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RdMonitoringData rdMonitoringData) {
        return toAjax(rdMonitoringDataService.updateRdMonitoringData(rdMonitoringData));
    }

    /**
     * 删除检测数据
     */
    @RequiresPermissions("road:monitoring_data:remove")
    @Log(title = "检测数据", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(rdMonitoringDataService.deleteRdMonitoringDataByIds(ids));
    }


}

